home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / Texinfo2HTML.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-30  |  10KB  |  349 lines

  1. /* Rexx program to convert .texinfo file to .html
  2.  *
  3.  * Also processes some amigaguide commands
  4.  *
  5.  * Only works on specific @commands!!
  6.  *
  7.  * SLOW
  8.  *
  9.  * $VER: texinfo2HTML.rexx 1.2 (2.2.94)
  10.  *
  11.  */
  12.  
  13. parse arg arg1 arg2 arg3
  14.  
  15. arg2 = strip(arg2)
  16. arg3 = strip(arg3)
  17. move = 0
  18.  
  19. if open('infile',arg1,'r') then do
  20.  if open('texinfofile',arg3,'w') then do
  21.     if open('outfile',arg2,'w') then do
  22.         line = myreadln()
  23.         do while ~eof('infile')
  24.             if substr(line,1,1) = "@" then do
  25.                 w = upper(word(line,1))
  26.                 select
  27.                     when w = "@@REMARK" then
  28.                         nop
  29.                     when w = "@@FONT" then
  30.                         nop
  31.                     when w = "@CINDEX" then
  32.                         nop
  33.                     when w = "@SETTITLE" then
  34.                         call writeln('outfile',"<TITLE>"mystrip(delword(line,1,1))"</TITLE>")
  35.                     when w = "@PARAGRAPHINDENT" then
  36.                         nop
  37.                     when w = "@NODE" then do
  38.                         say line
  39.                         if upper(word(line,2)) ~= "TOP" then do
  40.                             call close('outfile')
  41.                             ts = delword(line,1,1)
  42.                             t = index(ts,",") 
  43.                             if t>0 then
  44.                                 arg2 = mystrip(left(ts,t-1))||".html"
  45.                             else
  46.                                 arg2 = mystrip(ts)||".html"
  47.                             if ~open('outfile',arg2,'w') then do
  48.                                 say "Error opening '"arg2"'"
  49.                                 call close()
  50.                                 return
  51.                             end
  52.                         end
  53.                     end
  54.                     when w = "@TOP" then do
  55.                         ts = mystrip(delword(line,1,1))
  56.                         call writeln('outfile',"<TITLE>"ts"</TITLE>")
  57.                         call writeln('outfile',"<H1>"ts"</H1>")
  58.                         call writeln('outfile',"<HR>")
  59.                         up1 = "<A HREF="arg2"><img src=Images/Up></A><P>"
  60.                     end
  61.                     when w = "@CHAPTER" then do
  62.                         ts = mystrip(delword(line,1,1))
  63.                         call writeln('outfile',"<TITLE>"ts"</TITLE>")
  64.                         call writeln('outfile',"<H1>"ts"</H1>")
  65.                         call writeln('outfile',"<HR>")
  66.                         call writeln('outfile',up1)
  67.                         up2 = "<A HREF="arg2"><img src=Images/Up></A><P>"
  68.                     end
  69.                     when w = "@UNNUMBEREDSEC" then do
  70.                         ts = mystrip(delword(line,1,1))
  71.                         call writeln('outfile',"<TITLE>"ts"</TITLE>")
  72.                         call writeln('outfile',"<H2>"ts"</H2>")
  73.                         call writeln('outfile',"<HR>")
  74.                         call writeln('outfile',up2)
  75.                         up3 = "<A HREF="arg2"><img src=Images/Up></A><P>"
  76.                     end
  77.                     when w = "@UNNUMBEREDSUBSEC" then do
  78.                         ts = mystrip(delword(line,1,1))
  79.                         call writeln('outfile',"<TITLE>"ts"</TITLE>")
  80.                         call writeln('outfile',"<H3>"ts"</H3>")
  81.                         call writeln('outfile',"<HR>")
  82.                         call writeln('outfile',up3)
  83.                         up4 = "<A HREF="arg2"><img src=Images/Up></A><P>"
  84.                     end
  85.                     when w = "@UNNUMBEREDSUBSUBSEC" then do
  86.                         ts = mystrip(delword(line,1,1))
  87.                         call writeln('outfile',"<TITLE>"ts"</TITLE>")
  88.                         call writeln('outfile',"<H4>"ts"</H4>")
  89.                         call writeln('outfile',"<HR>")
  90.                         call writeln('outfile',up4)
  91.                         up5 = "<A HREF="arg2"><img src=Images/Up></A><P>"
  92.                     end
  93.                     when w = "@UNNUMBERED" then do
  94.                         ts = mystrip(delword(line,1,1))
  95.                         call writeln('outfile',"<TITLE>"ts"</TITLE>")
  96.                         call writeln('outfile',"<H2>"ts"</H2>")
  97.                         call writeln('outfile',"<HR>")
  98.                         call writeln('outfile',up5)
  99.                         up2 = "<A HREF="arg2"><img src=Images/Up></A><P>"
  100.                     end
  101.                     when w = "@ITEMIZE" then
  102.                         call convertitemize()
  103.                     when w = "@EXAMPLE" then do
  104.                         call writeln('outfile',"<PRE>")
  105.                         line = myreadln()
  106.                         do while ~eof('infile') & (upper(line) ~= "@END EXAMPLE")
  107.                             call writeln('outfile',mystrip(line))
  108.                             line = myreadln()
  109.                         end
  110.                         call writeln('outfile',"</PRE>")
  111.                     end
  112.                     when w = "@MENU" then do
  113.                         line = myreadln()
  114.                         call writeln('outfile',"<MENU>")
  115.                         do while ~eof('infile') & substr(line,1,1) ~= "*"
  116.                             call writeln('outfile',"<B>"line"</B>")
  117.                             line = myreadln()
  118.                         end
  119.                         do while ~eof('infile') & upper(line) ~= "@END MENU"
  120.                             select
  121.                                 when line = "" then
  122.                                     call writeln('outfile',"<P>")
  123.                                 when substr(line,1,1) = "*" then do
  124.                                     if move>0 then do
  125.                                         move = 0
  126.                                         call writeln('outfile',"</UL>")
  127.                                     end
  128.                                     call writech('outfile',"<LI><A HREF=")
  129.                                     call writech('outfile',mystrip(strip(substr(line,index(line,":")+1),,"  "))||".html>")    /* One is NBSP */
  130.                                     call writeln('outfile',mystrip(strip(substr(line,3,index(line,":")-3),,"  "))||"</A>")    /* One is NBSP */
  131.                                 end
  132.                                 when line = "" then
  133.                                     call writeln('outfile',"<P>")
  134.                                 otherwise
  135.                                     if move=0 then do
  136.                                         call writech('outfile',"<UL>")
  137.                                         move = 1
  138.                                     end
  139.                                     call writeln('outfile',myconvert(line))
  140.                             end
  141.                             line = myreadln()
  142.                         end
  143.                         if move>0 then do
  144.                             move = 0
  145.                             call writeln('outfile',"</UL>")
  146.                         end
  147.                         call writeln('outfile',"</MENU>")
  148.                     end
  149.                     otherwise
  150.                         call writeln('outfile',myconvert(line))
  151.                 end
  152.             end
  153.             else
  154.                 if line = "" then
  155.                     call writeln('outfile',"<P>")
  156.                 else
  157.                     call writeln('outfile',myconvert(line))
  158.             line = myreadln()
  159.         end
  160.         call close('outfile')
  161.     end
  162.     else
  163.         say "Error opening '"arg2"'"
  164.     call close('texinfofile')
  165.  end
  166.  else
  167.     say "Error opening '"arg3"'"
  168.  call close('infile')
  169. end
  170. else do
  171.     say "Error opening '"arg1"'"
  172. end
  173. return
  174.  
  175. mystrip: procedure
  176.     parse arg line1
  177.     if index(line1,"@") > 0 then do
  178.         line2 = ""
  179.         do i=1 to length(line1) by 1
  180.             if substr(line1,i,1) = "@" then
  181.                 select
  182.                     when substr(line1,i,5) = "@ref{" then do
  183.                         line3 = substr(line1,i+5)
  184.                         line3 = substr(line3,1,index(line3,"}")-1)
  185.                         line2 = line2 || mystrip(substr(line3,index(line3,",")+1))||" "
  186.                         i = index(line1,"}",i)
  187.                     end
  188.                     when substr(line1,i,6) = "@xref{" then do
  189.                         line3 = substr(line1,i+6)
  190.                         line3 = substr(line3,1,index(line3,"}")-1)
  191.                         line2 = line2 || mystrip(substr(line3,index(line3,",")+1))||" "
  192.                         i = index(line1,"}",i)
  193.                     end
  194.                     when substr(line1,i,5) = '@@@{"' then do
  195.                         line3 = substr(line1,i+5)
  196.                         line3 = substr(line3,1,index(line3,"/Main")-1)
  197.                         line2 = line2 || mystrip(substr(line3,1,index(line3,"ALINK")-3))||" "
  198.                         i = index(line1,"}",i)
  199.                     end
  200.                     when substr(line1,i,7) = "@@@{u@}" then
  201.                         i = i+6
  202.                     when substr(line1,i,8) = "@@@{uu@}" then
  203.                         i = i+7
  204.                     when substr(line1,i,2) = "@@" then do
  205.                         line2 = line2 || "@"
  206.                         i = i + 1
  207.                     end
  208.                     otherwise
  209.                         do j=i to length(line1) by 1 while substr(line1,j,1) ~= "{"
  210.                             nop
  211.                         end
  212.                         i = j
  213.                 end
  214.             else
  215.                 if substr(line1,i,1) = "}" then
  216.                     nop
  217.                 else
  218.                     line2 = line2 || substr(line1,i,1)
  219.         end
  220.         return line2
  221.     end
  222.     else
  223.         return line1
  224.  
  225. myconvert: procedure
  226.     parse arg line1
  227.     if index(line1,"@") > 0 then do
  228.         line2 = ""
  229.         do i=1 to length(line1) by 1
  230.             if substr(line1,i,1) = "@" then
  231.                 select
  232.                     when substr(line1,i,5) = "@ref{" then do
  233.                         line3 = substr(line1,i+5)
  234.                         line3 = substr(line3,1,index(line3,"}")-1)
  235.                         line2 = line2 || "<A HREF="
  236.                         line2 = line2 || mystrip(substr(line3,1,index(line3,",")-1)) || ".html>"
  237.                         line2 = line2 || mystrip(substr(line3,index(line3,",")+1)) || "</A>"
  238.                         i = index(line1,"}",i)
  239.                     end
  240.                     when substr(line1,i,6) = "@xref{" then do
  241.                         line3 = substr(line1,i+6)
  242.                         line3 = substr(line3,1,index(line3,"}")-1)
  243.                         line2 = line2 || "See <A HREF="
  244.                         line2 = line2 || mystrip(substr(line3,1,index(line3,",")-1))||".html>"
  245.                         line2 = line2 || mystrip(substr(line3,index(line3,",")+1))||"</A>"
  246.                         i = index(line1,"}",i)
  247.                     end
  248.                     when substr(line1,i,5) = '@@@{"' then do
  249.                         line3 = substr(line1,i+5)
  250.                         line3 = substr(line3,1,index(line3,"/Main")-1)
  251.                         line2 = line2 || "<A HREF=/"
  252.                         line2 = line2 || mystrip(substr(line3,index(line3,"ALINK")+7))||">"
  253.                         line2 = line2 || mystrip(substr(line3,1,index(line3,"ALINK")-3))||"</A>"
  254.                         i = index(line1,"}",i)
  255.                     end
  256.                     when substr(line1,i,7) = "@@@{u@}" then do
  257.                         i = i+6
  258.                         line2 = line2 || "<B>"
  259.                     end
  260.                     when substr(line1,i,8) = "@@@{uu@}" then do
  261.                         i = i+7
  262.                         line2 = line2 || "</B>"
  263.                     end
  264.                     when substr(line1,i,2) = "@@" then do
  265.                         line2 = line2 || "@"
  266.                         i = i + 1
  267.                     end
  268.                     when upper(substr(line1,i,6)) = "@CODE{" then do
  269.                         line2 = line2 || "<B>"
  270.                         do j=i+6 to length(line1) by 1 while substr(line1,j,1) ~= "}"
  271.                             line2 = line2 || substr(line1,j,1)
  272.                         end
  273.                         line2 = line2 || "</B>"
  274.                         i = j
  275.                     end
  276.                     when upper(substr(line1,i,5)) = "@DFN{" then do
  277.                         line2 = line2 || "<I>"
  278.                         do j=i+5 to length(line1) by 1 while substr(line1,j,1) ~= "}"
  279.                             line2 = line2 || substr(line1,j,1)
  280.                         end
  281.                         line2 = line2 || "</I>"
  282.                         i = j
  283.                     end
  284.                     otherwise
  285.                         do j=i to length(line1) by 1 while substr(line1,j,1) ~= "{"
  286.                             nop
  287.                         end
  288.                 end
  289.             else
  290.                 if substr(line1,i,1) = "}" then
  291.                     nop
  292.                 else
  293.                     line2 = line2 || substr(line1,i,1)
  294.         end
  295.         return line2
  296.     end
  297.     else
  298.         return line1
  299.  
  300. convertitemize: procedure expose line infile outfile
  301.     call writeln('outfile',"<UL>")
  302.     line = myreadln()
  303.     do while ~eof('infile') & (upper(line) ~= "@END ITEMIZE")
  304.         select
  305.             when line = "" then
  306.                 call writeln('outfile',"<P>")
  307.             when upper(substr(line,1,8)) = "@ITEMIZE" then
  308.                 call convertitemize()
  309.             when upper(substr(line,1,5)) = "@ITEM" then
  310.                 call writeln('outfile',"<LI>"||myconvert(delword(line,1,1)))
  311.             otherwise
  312.                 call writeln('outfile',myconvert(line))
  313.         end
  314.         line = myreadln()
  315.     end
  316.     call writeln('outfile',"<P>")
  317.     call writeln('outfile',"</UL>")
  318.     return
  319.  
  320. myreadln: procedure
  321.     flag = 1
  322.     line = readln('infile')
  323.     do while (flag>0) & ~eof('infile')
  324.         if substr(line,1,1) = "@" then do
  325.             w = upper(word(line,1))
  326.             select
  327.                 when w = "@HTML" then do
  328.                     call writeln('outfile',delword(line,1,1))
  329.                     line = readln('infile')
  330.                 end
  331.                 when w = "@HTMLOFF" then do
  332.                     line = readln('infile')
  333.                     do while (word(line,1) ~= "@HTMLON") & ~eof('infile')
  334.                         call writeln('texinfofile',line)
  335.                         line = readln('infile')
  336.                     end
  337.                     if ~eof('infile') then
  338.                         line = readln('infile')
  339.                 end
  340.                 otherwise
  341.                     flag=0
  342.             end
  343.         end
  344.         else
  345.             flag = 0
  346.     end
  347.     call writeln('texinfofile',line)
  348.     return line
  349.